package com.ztx.service.caiwu.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Repository;

import com.ztx.model.JklsVO;
import com.ztx.model.JklsViewVO;
import com.ztx.pagemodel.SessionInfo;
import com.ztx.pagemodel.easyui.DataGrid;
import com.ztx.pagemodel.easyui.PageHelper;
import com.ztx.service.caiwu.IJklsAuditService;

@Repository
public class JklsAuditService implements IJklsAuditService {

	@Resource
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public DataGrid<JklsViewVO> jklsDatagrid(PageHelper ph, JklsVO params) {

		DataGrid<JklsViewVO> datagrid = new DataGrid<JklsViewVO>();

		long total = sqlSessionTemplate.selectOne(JklsVO.class.getName()
				+ ".auditListCount", params);

		List<JklsVO> jklsList = sqlSessionTemplate.selectList(
				JklsVO.class.getName() + ".auditList", params,
				ph.getRowBounds());

		List<JklsViewVO> viewvoList = new ArrayList<JklsViewVO>();
		for (int i = 0; i < jklsList.size(); i++) {
			JklsViewVO viewvo = new JklsViewVO();
			BeanUtils.copyProperties(jklsList.get(i), viewvo);
			viewvoList.add(viewvo);
		}
		// 数据转换
		datagrid.setTotal(total);
		datagrid.setRows(viewvoList);
		return datagrid;
	}

	@Override
	public void doAuditPass(long id, SessionInfo session) throws Exception {
		sqlSessionTemplate.update(JklsVO.class.getName() + ".updateJklsStatus",
				id);
	}

	@Override
	public void editAndPass(JklsViewVO jkls, SessionInfo session)
			throws Exception {
		sqlSessionTemplate.update(JklsVO.class.getName()
				+ ".updateJkls", jkls);

	}

}
